﻿using ICSharpCode.SharpZipLib.GZip;
using ICSharpCode.SharpZipLib.Zip;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RecordBill.Core
{
   public class DecompressHelper
    {
       public static List<string> ExtractFiles(string zipPath, string password)
        {
            List<string> list = new List<string>();
            try
            {
                using (var fs = File.OpenRead(zipPath))
                {
                    var zip = new ZipFile(fs);
                    zip.Password = password;
                    foreach (ZipEntry entry in zip)
                    {
                        if (!entry.IsFile) continue; // Skip directories
                        var outputPath = Path.Combine(Path.GetDirectoryName(zipPath), entry.Name);
                        var outputDirectory = Path.GetDirectoryName(outputPath);
                        if (!Directory.Exists(outputDirectory)) Directory.CreateDirectory(outputDirectory);
                        var outputStream = File.Create(outputPath);
                        zip.GetInputStream(entry).CopyTo(outputStream);
                        outputStream.Close();
                        list.Add(outputPath);
                    }
                }
                return list;
            }
            catch (Exception ex)
            {
                Console.WriteLine($"解压过程中出错: {ex.Message}");
                return null;
            }
        }
    }
}
